package StudyCode.summary.mycollection;

import java.util.ArrayList;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UnionOfTwoArrayList {
	public static ArrayList<Integer> union(ArrayList<Integer> setA,
	                                       ArrayList<Integer> setB) throws IllegalArgumentException {
		ArrayList<Integer> returnValues = new ArrayList<Integer>();

		for (int i = 0; i < setA.size(); i++) {
			boolean isAddable = true;
			for (int j = 0; j < returnValues.size() && isAddable; j++) {
				isAddable = setA.get(i) != returnValues.get(j);
			}
			if (isAddable) {
				returnValues.add(setA.get(i));
			}
		}

		for (int i = 0; i < setB.size(); i++) {
			boolean isAddable = true;
			for (int j = 0; j < returnValues.size() && isAddable; j++) {
				isAddable = setB.get(i) != returnValues.get(j);
			}
			if (isAddable) {
				returnValues.add(setB.get(i));
			}
		}

		return returnValues;
	}
}
